package cn.xscrum.demo.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.xscrum.common.annotation.Log;
import cn.xscrum.common.enums.BusinessType;
import cn.xscrum.demo.domain.PassengerFlow;
import cn.xscrum.demo.service.IPassengerFlowService;
import cn.xscrum.common.core.controller.BaseController;
import cn.xscrum.common.core.domain.AjaxResult;
import cn.xscrum.common.utils.poi.ExcelUtil;
import cn.xscrum.common.core.page.TableDataInfo;

/**
 * 换乘客流换乘变换Controller
 * 
 * @author hyq
 * @date 2020-11-25
 */
@Controller
@RequestMapping("/demo/flow")
public class PassengerFlowController extends BaseController
{
    private String prefix = "demo/flow";

    @Autowired
    private IPassengerFlowService passengerFlowService;

    @RequiresPermissions("demo:flow:view")
    @GetMapping()
    public String flow()
    {
        return prefix + "/flow";
    }

    /**
	 * 查询换乘客流换乘变换列表
     */
    @RequiresPermissions("demo:flow:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PassengerFlow passengerFlow)
    {
        startPage();
        List<PassengerFlow> list = passengerFlowService.selectPassengerFlowList(passengerFlow);
        return getDataTable(list);
    }

    /**
	 * 导出换乘客流换乘变换列表
     */
    @RequiresPermissions("demo:flow:export")
    @Log(title = "换乘客流换乘变换", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PassengerFlow passengerFlow)
    {
        List<PassengerFlow> list = passengerFlowService.selectPassengerFlowList(passengerFlow);
        ExcelUtil<PassengerFlow> util = new ExcelUtil<PassengerFlow>(PassengerFlow.class);
        return util.exportExcel(list, "flow");
    }

    /**
	 * 新增换乘客流换乘变换
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
	 * 新增保存换乘客流换乘变换
     */
    @RequiresPermissions("demo:flow:add")
    @Log(title = "换乘客流换乘变换", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PassengerFlow passengerFlow)
    {
        return toAjax(passengerFlowService.insertPassengerFlow(passengerFlow));
    }

    /**
	 * 修改换乘客流换乘变换
     */
    @GetMapping("/edit/{no5}")
    public String edit(@PathVariable("no5") Long no5, ModelMap mmap)
    {
        PassengerFlow passengerFlow = passengerFlowService.selectPassengerFlowById(no5);
        mmap.put("passengerFlow", passengerFlow);
        return prefix + "/edit";
    }

    /**
	 * 修改保存换乘客流换乘变换
     */
    @RequiresPermissions("demo:flow:edit")
    @Log(title = "换乘客流换乘变换", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PassengerFlow passengerFlow)
    {
        return toAjax(passengerFlowService.updatePassengerFlow(passengerFlow));
    }

    /**
	 * 删除换乘客流换乘变换
     */
    @RequiresPermissions("demo:flow:remove")
    @Log(title = "换乘客流换乘变换", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(passengerFlowService.deletePassengerFlowByIds(ids));
    }
}
